<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/common/meta.jsp" %>
<title>Insert title here</title>
<script type="text/javascript">
	$(document).ready(function(){
		$("#typetree a").click(nodeClick);
		});
	var idInput = "${param['idInput']}";
	var nameInput = "${param['nameInput']}";
	var form = "${param['form']}";
	var dlgID = "${param['dlgID']}";


	/**
	cascadeName = true 级联名称  
	**/
	var cascadeName = "${param['cascadeName']}";
	
	/**
	leafNode = true 只能选叶子节点  
	**/
	var leafNode =  "${param['leafNode']}";
	var oldID = $("#"+form+" #"+idInput).val();
	var oldName = $("#"+form+" #"+nameInput).val();
	var dlg = $.pdialog;
	var id = -1;
	var isLeaf = false;
	function nodeClick(){
		var name = $(this).text();		
		var style = $((this)).attr("class");
		if(style=="typeLeaf"){
			isLeaf = true;
			}
		else{
			isLeaf = false;
					}
	 	id = this.id;
	 	if(cascadeName=="true"){
	 	name = getAllParentsName(this);
	 	name = name.substr(name.indexOf(" | ")+3);
	 	}
		$("#"+form+" #"+idInput).val(id);
		$("#"+form+" #"+nameInput).val(name);
		}
	function ok(){
		if(leafNode=="true"&&isLeaf==true){
			dlg.close(dlgID);
			}
		else{
			alertMsg.info("对不起，请选择至子节点！");
			}
		
		}
	function cancel(){
		$("#"+form+" #"+idInput).val(oldID);
		$("#"+form+" #"+nameInput).val(oldName);
		dlg.close(dlgID);
		}
	function getAllParentsName(a){
		var id = a.id;
		var parentId = a.parentId;
		var parentA = $("#typetree a[id='"+parentId+"']");
		var name = $(a).text();
		if(parentA.length>0){
			 name = getAllParentsName(parentA.get(0))+" | "+name;			
			}
		return name;
		}
</script>
</head>
<body>

<div id="typetree" style=" float:left; display:block; margin:10px; overflow:auto; width:200px; height:95%; border:solid 1px #CCC; line-height:21px; background:#FFF;">
<ul class="tree treeFolder expand" >
	${ul }
</ul>
</div>
<div style="height:120;width:1;"></div>
<div class="formBar" style="text-align:center;">
<div style="width:100px;height:100%;">
				<ul>
					<li style="float:left;"><div class="buttonActive"><div class="buttonContent"><button type="Button" onclick="ok()">确定</button></div></div>
					</li>
					<li style="float:left;">
						<div class="button"><div class="buttonContent"><button type="Button" onclick="cancel()">取消</button></div></div>
					</li>
				</ul>
</div>
</div>
</body>
</html>